package com.thingple.settings;

import android.net.Uri;
import android.util.Log;

/**
 *
 * Created by lism on 2017/11/23.
 */

public class Common {

    private static String TAG = "Common";

    public static Uri parseUrl(String url) {
        return parseUrl(url, null);
    }

    public static Uri parseUrl(String root, String url) {
        Uri uri = null;
        String prefix = root;
        String suffix = url;
        if (prefix == null) {
            return null;
        }
        if (suffix == null) {
            suffix = "";
        }
        if (prefix.endsWith("/") && suffix.startsWith("/")) {
            suffix = suffix.substring(1);
        }
        if (prefix.endsWith("/") && suffix.startsWith("/")) {
            prefix = prefix + "/";
        }
        try {
            uri = Uri.parse(prefix + suffix);
        } catch (Exception e) {
            Log.e(TAG, "uri转换异常", e);
        }
        return uri;
    }
}
